<template>
  <div class="community-item" @click="LinkTo">
    <div class="item-header">
      <div class="header-left">
        <div class="header-left-avatar">
          <van-image round width="35" cover height="35" :src="comItemInfo.avatarUrl" />
        </div>
        <div class="header-left-info">
          <div class="user-name">
            <span class="name">{{ comItemInfo.userName }}</span>
            <!-- 根据等级展示不同的标签样式 -->
            <van-tag type="success" v-if="comItemInfo.level <= 5">Lv.{{ comItemInfo.level }}</van-tag>
            <van-tag type="primary" v-else-if="comItemInfo.level <= 10">Lv.{{ comItemInfo.level }}</van-tag>
            <van-tag type="warning" v-else-if="comItemInfo.level <= 15">Lv.{{ comItemInfo.level }}</van-tag>
            <van-tag type="danger" v-else>Lv.{{ comItemInfo.level }}</van-tag>
          </div>
          <div class="time-tag">{{ comItemInfo.time }}·{{ comItemInfo.tag }}</div>
        </div>
      </div>
      <div class="header-right">
        <div class="header-right-thumbs">
          <van-icon name="good-job" color="#c8c9cc" />
          {{ comItemInfo.thumbs }}
        </div>
        <div class="header-right-comment">
          <van-icon name="comment" color="#c8c9cc" />
          {{ comItemInfo.comment }}
        </div>
      </div>
    </div>
    <div class="item-content">
      <div class="item-content-title">{{ comItemInfo.contentTitle }}</div>
      <div class="item-content-text van-multi-ellipsis--l3">{{ comItemInfo.contentText }}</div>
      <div class="item-content-img">
        <template v-for="item in comItemInfo.contentImgUrl">
          <van-image width="120" height="80" radius="2px" fit="cover" :src="item" @click.stop="onClick(item)" />
        </template>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, defineProps } from 'vue';

import { ImagePreview } from 'vant';
import router from '../../route';

// 父组件传值
let props = defineProps({
  comItemInfo: Object
})

const onClick = (item) => {
  const imgLists = [item]
  ImagePreview(imgLists)
}

const LinkTo = () => {
  console.log('跳转到社区动态详情', props.comItemInfo.id);
  router.push({
    path: '/artdetail',
    query: {
      id: props.comItemInfo.id
    }
  })
}

</script>

<style scoped>
.community-item {
  padding: 12px;
  font-size: 0;
  margin-bottom: 3px;
  background-color: #fff;
}

.item-header {
  display: flex;
  justify-content: space-between;
}

.header-left {
  display: flex;
}

.header-left-info {
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.header-left-info .user-name {
  /* 用户名字体 */
  font-size: 15px;
  color: #323233;
  display: flex;
  align-items: center;
}

.header-left-info .user-name .name {
  margin-right: 5px;
}

.header-left-info .time-tag {
  /* 时间以及分类字体 */
  font-size: 11px;
  color: #969799;
}

.header-right {
  /* 点赞以及评论字体 */
  font-size: 14px;
  color: #c8c9cc;
  display: flex;
}

.header-right .header-right-thumbs {
  margin-right: 10px;
}

.item-content {
  margin-top: 15px;
}

.item-content .item-content-title {
  /* 内容标题字体 */
  font-size: 16px;
  color: #323233;
}

.item-content .item-content-text {
  margin-top: 8px;
  /* 内容正文预览字体 */
  font-size: 15px;
  color: #646566;
  line-height: 20px;
}

.item-content .item-content-img {
  margin-top: 8px;
  /* background-color: lightcoral; */
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
